import 'package:floor/floor.dart' as sqflite;
import 'package:flutter/material.dart';

abstract class AbsDeviceConfig {
  /// 设备 icon
  int deviceIcon();

  int deviceIcon2();

  /// 设备名 (比如蓝牙名)
  String deviceName();

  /// 型号
  String deviceModel();

  /// 设备宽度
  double deviceWidth();

  /// 设备高度
  double deviceHeight();

  /// A 面背景图
  int deviceForeBg();

  int deviceForeBgHeight();

  /// 支持的颜色
  Map<int, ColorValue> enableColors();

  /// B 面背景图
  int deviceBackBg();

  int deviceBackBgHeight();

  /// 是否支持双屏
  bool enableBothScreen() => true;

  /// 标题
  String deviceTitle();

  /// 模板数据
  AbsTemplateDataProvider? getTemplateData();

  /// 尺寸 (内部逻辑用)
  double size();

  /// 获取宽高比
  double getDeviceRatio() {
    return deviceHeight() / deviceWidth();
  }

  /// 获取缩放后的设备大小
  int getDeviceSize() {
    return (size() * 100).toInt();
  }

  /// 获取可用颜色的标题列表
  List<String> enableColorTitles() {
    return enableColors().values.map((e) => e.title).toList();
  }

  /// 获取可用颜色值列表
  List<int> enableColorLists() {
    return enableColors().values.map((e) => e.color).toList();
  }

  /// 通过索引获取颜色
  int getColorByIndex(int index) {
    return enableColors()[index]?.color ?? Colors.black.value;
  }
}

class ColorValue {
  final String title;
  final int color;

  ColorValue({required this.title, required this.color});
}

abstract class AbsTemplateDataProvider {
  final AbsDeviceConfig config;

  AbsTemplateDataProvider(this.config);

  int deviceSize() => config.getDeviceSize();

  int colorTotals() => config.enableColors().length;

  /// 插入模板数据
  void createTemplateDatas(sqflite.Database db);

  /// 数据升级
  void onUpgrade(sqflite.Database db, int oldVersion, int newVersion);

  @override
  bool operator ==(Object other) {
    if (identical(this, other)) return true;
    if (other.runtimeType != runtimeType) return false;
    return other is AbsTemplateDataProvider &&
        config.deviceModel() == other.config.deviceModel();
  }

  @override
  int get hashCode => config.hashCode;
}


enum DeviceGroup {
  TABLECARD("桌牌"),
  BEDSIDECARD("床头卡"),
  DIGITALSIGNAGE("数字标牌");

  final String label;   // 设备标签

  const DeviceGroup(this.label);

}

